<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Canvas-裁剪</title>
</head>
<body>
<canvas id="canvas"></canvas>
</body>
<script>
  let canvas = document.querySelector('#canvas');
  let ctx = canvas.getContext('2d');
  let img = new Image();
  img.src = 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2298249555,303155384&fm=26&gp=0.jpg';
  img.onload = () => {
    ctx.drawImage(img, 0, 0)
  };

  let path = new Path2D();
  path.moveTo(100, 30);
  path.lineTo(60, 30);
  path.lineTo(60, 60);
  path.closePath();
  ctx.clip(path)
</script>
</html>
